<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of database
 *
 * @author Andi
 */
class database {
    //put your code here
    var $locationSQL   = 'localhost';
    var $usernameSQL   = 'root';
    var $passwordSQL   = '';
    var $dbSQL         = 'progin2';
    var $con;

    function  __construct() {
        $this->connect();
    }


    function connect(){
        $this->con = mysql_connect($this->locationSQL,$this->usernameSQL,$this->passwordSQL);
        if (!$this->con) {
            die('Could not connect: ' . mysql_error());
        }
        mysql_select_db($this->dbSQL,$this->con) or
                die ("could not select database");
    }

    function disconect(){
        mysql_close($this->con);
    }

    function query($sql) {
        if (!mysql_query($sql)) {
            die('Error: ' . mysql_error());
        }
    }

    function retrieve($table){
        $result = mysql_query("SELECT * FROM $table");
        return $result;
    }

    function search($table,$column,$keyword){
        $sql = "SELECT * FROM $table WHERE $column = '$keyword'";
        $result = mysql_query($sql);
        return $result;
    }

    function searchUserID($user_name,$password){
        $sql = "SELECT * FROM user WHERE user_name = '$user_name' AND password = '$password'";
        $result = mysql_query($sql);
        $row = mysql_fetch_array($result);
        return $row['user_id']; 
    }

    function update($table,$col_id,$id,$column_change,$new_val){
        $sql = "UPDATE $table SET $column_change = '$new_val' WHERE $col_id = '$id'";
        mysql_query($sql);
    }

    function delete($table,$col_id,$id){
        $sql = "DELETE FROM $table WHERE $col_id = '$id'";
        mysql_query($sql);
    }
}
?>